<template>
	<!-- 头部搜索框 -->
	<uni-search-bar @confirm="toSearch" placeholder="请输入搜索公交地铁路线" v-model="searchKey" />
	<!-- 轮播 -->
	<swiper style="height: 200px;" :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000">
		<swiper-item v-for="(item,index) in lunboList" :key="index">
			<view class="swiper-item">
				<image style="width: 100%;" :src="item.url" mode=""></image>
			</view>
		</swiper-item>
	</swiper>

	<!-- 和风天气展示部分 -->
	<view class="weather">

		<view class="icon" style="width: 100rpx;height: 100rpx; ">
			<image style="width: 100%;height: 100%;" :src="'/static/weather/icons/'+ weatherNow.icon +'.svg'" mode="">
			</image>
		</view>
		<!-- 实时温度 -->
		<view class="text" style="font-size: 50rpx;margin-left: 10px;">
			{{weatherNow.temp}}°C
		</view>
		<!-- 实时天气 -->
		<view class="text" style="font-size: 34rpx;margin-left: 10px;">
			{{weatherNow.text}}
		</view>
		<!-- 风向以及风力等级 -->
		<view class="text" style=" margin-left: 10rpx;">
			{{weatherNow.windDir}} {{weatherNow.windScale}}级
		</view>
		<view>
			<view class="text" style="margin-left: 10rpx;">
				体感温度： {{weatherNow.feelsLike }}°C
			</view>
			<view class="text" style="margin-left: 10rpx;">
				湿度： {{weatherNow.humidity }}%
			</view>
		</view>
	</view>

	<!-- 分类设计 -->
	<uni-grid :show-border="false" :column="4" @change="changeGrid">
		<uni-grid-item v-for="(item,index) in gridData" :index="index">
			<view class="grid-item-box" style="background-color: #fff;">
				<uni-icons :type="item.icon" :size="30" :color="item.color" />
				<text class="text">{{item.title}}</text>
			</view>
		</uni-grid-item>

	</uni-grid>

	<!-- 视频 -->
	<!-- 一个内容不需要做列表渲染 -->
	<div class="video">
		<video style="width: 100%;" :src="viodeList" mode=""></video>
	</div>
	<!-- 景点推荐 -->
	<uni-section title="景点推荐" type="line" titleFontSize="18px" padding />
	<view class="jiang">
		<view class="item" :column="2" v-for="(item,index) in seniclist" @tap="toDetails(item.objectId)">
			<view class="pic">
				<image :src="item.img" mode=""></image>
			</view>
			<vieew class="msg">
				<view class="name">{{item.name}}</view>
				<view class="intro">{{item.intro}}</view>
			</vieew>
		</view>
	</view>
</template>

<script setup>
	import {
		CONFIGS
	} from "../../utils/config"
	import {
		onLoad
	} from "@dcloudio/uni-app"
	import {
		ref
	} from 'vue'
	import {
		CONFIG
	} from "../../utils/config"
	const seaechKey = ref("")

	onLoad(() => {
		getLunbo()
		getCurrentPoss()
		getWeather()
		getviode()
	})

	const searchKey = ref("")

	function toSearch() {


		if (searchKey.value == "") {
			uni.showToast({
				title: "请输入查询的公交地图路线",
				icon: "none"
			})
		} else {
			window.location.href =
				`https://uri.amap.com/line?name=${searchKey.value}&city=029&callnative=0`
		}
	}
	//轮播的数据
	const lunboList = ref([])
	// 获取轮播数据
	async function getLunbo() {
		let res = await uni.$get(CONFIG.leanCloud_url + "/1.1/classes/Lunbo")
		if (res.statusCode == 200) {
			lunboList.value = res.data.results
		}
		console.log(lunboList.value);
	}

	//视频的数据
	const viodeList = ref({})
	// 获取视频数据
	async function getviode() {
		let res = await uni.$get(CONFIG.leanCloud_url + "/1.1/classes/viedo")
		if (res.statusCode == 200) {
			viodeList.value = res.data.results[0].url
		}
		console.log(viodeList.value);
	}
	// 坐标
	function getCurrentPoss() {
		uni.getLocation({
			success: function(res) {
				console.log('当前位置的经度' + res.longitude);
				console.log('当前位置的纬度' + res.latitude);
			},

		})
	}
	// 和风天气
	let weatherNow = ref({})
	async function getWeather() {
		let res = await uni.$get(CONFIG.hefeng_locations, weatherNow.value)
		console.log(res)
		if (res.statusCode == 200) {
			weatherNow.value = res.data.now
			console.log(res.now)
		}
	}
	// 分类设计
	let gridData = [{
			title: '热映电影',
			icon: 'videocam',
			color: "red" //图标颜色

		},
		{
			title: '我在哪里',
			icon: 'paperplane',
			color: "red" //图标颜色

		},
		{
			title: '天气预报',
			icon: 'image-filled',
			color: "red" //图标颜色

		},
		{
			title: '小组分工',
			icon: 'search',
			color: "red" //图标颜色

		},
	]
	async function changeGrid(e) {
		//点击的序号
		let index = await e.detail.index
		// 根据不同的需要进行相应的跳转
		switch (index) {
			case 0:
				uni.navigateTo({
					url: "/pages/movie/movie"
				})
				break;
			case 1:
				uni.navigateTo({
					url: "/pages/playWebView/playWebView"
				})
				break;
			case 2:
				uni.navigateTo({
					url: "/pages/question/question"
				})
				break;
			case 3:
				uni.navigateTo({
					url: "/pages/group/group"
				})
				break;
		}
	}
	// 景点
	const type = ref(1)
	onLoad(() => {
		getSenic()
	})
	const seniclist = ref([])
	async function getSenic() {
		
		let query={
			"type":1
		}
		let querStr=JSON.stringify(query)
		console.log(query)
		console.log(querStr)
		let res = await uni.$get(CONFIGS.leancloud2_url + "/1.1/classes/Senicitem",{
			where:querStr
		})
		console.log(res)
		if(res.statusCode==200){
			seniclist.value=res.data.results
		}
		console.log(seniclist.value)
	}
	
</script>

<style lang="scss" scoped>
	.weather {
		height: 100rpx;
		border: 1px solid #ccc;
		margin: 5px;
		border-radius: 5px;
		display: flex;
		justify-content: space-between;
		padding: 10rpx;
		align-items: center;
	}

	.grid-item-box {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: space-around;
	}
	.jiang{
		.item {
		    display: flex;
		    flex-direction: row;
		    border-bottom: 1px solid #ccc; /* 底部添加一条浅灰色分割线 */
		    padding: 10px 0;
		    margin: 0 10px;
		}
		
		/* 景点图片容器样式 */
		.pic {
		    width: 100px;
		    height: 100px;
		    margin-right: 10px;
		}
		
		/* 图片样式，设置合适的显示模式，这里以宽度固定，高度自适应为例 */
		.pic image {
		    width: 100%;
		    height: 100%;
		    display: block;
		    object-fit: cover;
		}
		
		/* 景点信息容器样式 */
		.msg {
		    flex: 1;
		    display: flex;
		    flex-direction: column;
		}
		
		/* 景点名称样式 */
		.name {
		    font-size: 16px;
		    font-weight: bold;
		    color: #333;
		    margin-bottom: 5px;
		}
		
		/* 景点介绍样式 */
		.intro {
		    font-size: 14px;
		    color: #666;
		}
	}
	
</style>